﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WxPayAPI
{
    public partial class ProductPage : System.Web.UI.Page
    {
        /// <summary>
        /// 调用js获取收货地址时需要传入的参数
        /// 格式：json串
        /// 包含以下字段：
        ///     appid：公众号id
        ///     scope: 填写“jsapi_address”，获得编辑地址权限
        ///     signType:签名方式，目前仅支持SHA1
        ///     addrSign: 签名，由appid、url、timestamp、noncestr、accesstoken参与签名
        ///     timeStamp：时间戳
        ///     nonceStr: 随机字符串
        /// </summary>
        public static string wxEditAddrParam {get;set;}

        protected void Page_Load(object sender, EventArgs e)
        {
            //Log.Info(this.GetType().ToString(), "page load");

            //Log.WiteWeijfLog(new HLDM.Website.Wap.weijf.lib.WeijfLog() {  });


            if (!IsPostBack)
            {
                JsApiPay jsApiPay = new JsApiPay(this);
                try
                {
                    //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                    jsApiPay.GetOpenidAndAccessToken();
                    if (!string.IsNullOrEmpty(jsApiPay.openid))
                    {
                        string total_fee = Request.QueryString["total_fee"];
                        string bodyStr = Request.QueryString["body"];
                        string orderCode = Request.QueryString["orderCode"];
                        string redirect_url = Request.QueryString["redirect_url"];

                        string openid = jsApiPay.openid;
                        string url = "JsApiPayPage.aspx?openid=" + openid + "&total_fee=" + total_fee + "&orderCode=" + orderCode + "&redirect_url=" + HttpUtility.UrlEncode(redirect_url) + "&body=" + bodyStr;
                        Response.Redirect(url);
                    }
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错，请重试" + "</span>");
                }
            }
        }  
    }
}